package day01_IO_JDBC.demo_JDBC_users.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DButils {

    //获得连接：

//    定义驱动常量
    private static final String DRIVER = "com.mysql.cj.jdbc.Driver";
    //    定义链接数据库的URL常量
    private static final String URL="jdbc:mysql://localhost:3306/airui_jdbc_demo";
    //    定义连接数据库的账号、密码常量：
    private static final String username= "root";
    private static final String password= "123456";

    public static Connection getConnection(){
        Connection connection = null;

        try {
//        加载驱动
            Class.forName(DRIVER);
//        通过DriverManager创建数据库连接对象connection
            connection = DriverManager.getConnection(URL,username,password);
            return connection;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return connection;
    }



}
